import request from '@/utils/request'
import { urlPrefix } from './config'
import { formatQuery } from './util'

export function getProjectList(page = 1, query) {
  let url = `${urlPrefix}/project?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function createProject(data) {
  return request({
    url: `${urlPrefix}/project`,
    method: 'post',
    data
  })
}

export function updateProject(data) {
  return request({
    url: `${urlPrefix}/project/${data.id}`,
    method: 'patch',
    data
  })
}

export function deleteProject(id) {
  return request({
    url: `${urlPrefix}/project/${id}`,
    method: 'delete'
  })
}

export function getAllProjectList() {
  return request({
    url: `${urlPrefix}/project_all`,
    method: 'get'
  })
}
